﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CSharp.Study.Entity;

namespace CSharp.Study.Test
{
    public class 模式匹配
    {
        public static void Go()
        {
            //var res = Enum.GetName(GetResult(Gesture.石头, Gesture.布));
            //var palyer = new 人物();
            //var res =  GetTypeByUser(palyer);
            //foreach(var user in User.Users)
            //{
            //    user.Evaluate = GetUserEvaluate(user);
            //}
            Status status1 = Status.Enabled;
            Status status2 = Status.Disabled;
            bool notActive = status1 is Status.Deleted or Status.Enabled;
            bool notActive2 = status2 is Status.Deleted or Status.Enabled;
            char a = 'f';
            var res = a is (>='a' and <='c') or (>='f' and <='h');

            object aa = 20.3;
            if(aa is double aaa ) 
            {
                Console.WriteLine(aaa.GetType());
            }
        }

        public enum Status
        {
            Enabled,
            Disabled,
            Deleted
        }

        #region 石头剪刀布
        private enum Gesture
        {
            石头 = 1,
            剪刀 = 2,
            布 = 3
        }

        private enum Result
        {
            赢 = 1,
            输 = -1,
            平局 = 0
        }

        private static Result GetResult(Gesture g1, Gesture g2) => (g1, g2) switch
        {
            (Gesture.石头, Gesture.石头) => Result.平局,
            (Gesture.石头, Gesture.剪刀) => Result.赢,
            (Gesture.石头, Gesture.布) => Result.输,
            (Gesture.剪刀, Gesture.石头) => Result.输,
            (Gesture.剪刀, Gesture.剪刀) => Result.平局,
            (Gesture.剪刀, Gesture.布) => Result.赢,
            (Gesture.布, Gesture.石头) => Result.赢,
            (Gesture.布, Gesture.剪刀) => Result.输,
            (Gesture.布, Gesture.布) => Result.平局,
            _ => throw new Exception("错误")
        };
        #endregion


        #region 对记录的匹配

        private record 人物(int 等级=5, decimal 攻击力=304);

        private static string GetTypeByUser(人物 palyer) =>
            palyer switch
            {
                (等级: > 20, 攻击力: > 200m) => "一流",
                (等级: > 10, 攻击力: > 100m) => "二流",
                (等级: > 5, 攻击力: > 50m) => "三流",
                人物 { 攻击力: > 300m } => "一流",
                _ => "不入流"
            };



        #endregion


        #region *对用户评价，对类的元素各种情况匹配*
        private static string GetUserEvaluate(CSharp.Study.Entity.User user) => (user.Name, user.Gender, user.Age, user.Height) switch
        {
            ("孔明", _, _, _) => $"{user.Name}牛批666",
            (_, 1, > 22, > 175) => $"{user.Name}牛批",
            (_, 0, > 18, > 160) => $"{user.Name}妹子牛批",
            _ => $"{user.Name}你不行啊"
        };
        #endregion

        public static bool IsLetter(Char c) => c is (>= 'a' and <= 'e') or (>= 'A' and <= 'E');

    }
}
